package com.tanhua.management.service;

import com.alibaba.dubbo.config.annotation.Reference;


import com.tanhua.dubbo.server.api.QuanZiApi;
import com.tanhua.dubbo.server.api.VideoListApi;
import com.tanhua.dubbo.server.pojo.Video;
import com.tanhua.dubbo.server.vo.PageInfo;
import com.tanhua.management.vo.PageResult;
import com.tanhua.management.vo.VideoListVo;

import com.tanhua.server.service.UserInfoService;

import org.apache.commons.lang3.RandomUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;


import javax.xml.crypto.Data;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class VideoListService {

    @Reference(version = "1.0.0")
    private VideoListApi videoListApi;


    @Autowired
    private RedisTemplate<String, String> redisTemplate;



    private UserInfoService userInfoService;

    private QuanZiApi quanZiApi;



    /**
     * 查看视频列表
     *
     * @param page
     * @param pageSize
     * @param sortProp
     * @param sortOrder
     * @param uid
     * @return
     */
    public PageResult  queryVideoList(Integer page, Integer pageSize, String sortProp, String sortOrder, Long uid) {

        PageResult pageResult = new PageResult();
        pageResult.setPage(page);
        pageResult.setPagesize(pageSize);
        pageResult.setPages(0);
        pageResult.setCounts(0);

        PageInfo pageInfo = this.videoListApi.queryVideoList(page, pageSize, sortProp, sortOrder, uid);

        List<Video> records = pageInfo.getRecords();

        List<VideoListVo> videoVoList = new ArrayList<>();


        for (Video record : records) {
            VideoListVo videoListVo = new VideoListVo();

            videoListVo.setUserId(record.getUserId());
            videoListVo.setPicUrl(record.getPicUrl());
            videoListVo.setCreateDate(record.getCreated());
            videoListVo.setVideoUrl(record.getVideoUrl());
            videoListVo.setId(record.getId().toHexString());
            //随机生成
            videoListVo.setReportCount(RandomUtils.nextInt(50, 80));//举报数量
            videoListVo.setLikeCount(RandomUtils.nextInt(50, 500));//点赞数量
            videoListVo.setCommentCount(RandomUtils.nextInt(0, 50));
            videoListVo.setForwardingCount(RandomUtils.nextInt(0, 50));

            videoVoList.add(videoListVo);
        }

            //装入总数
            pageResult.setCounts(pageInfo.getTotal());

            pageResult.setItems(videoVoList);

            return pageResult;
        }
    }
